package ar.uade.distribuidas.tpo.dba.servicio;

import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import ar.uade.distribuidas.tpo.base.remoto.IGestionCotizacion;
import ar.uade.distribuidas.tpo.base.remoto.IGestionListaPrecio;
import ar.uade.distribuidas.tpo.base.remoto.IGestionRodamientos;
import ar.uade.distribuidas.tpo.base.remoto.IGestionSolicitudDeCotizacion;
import ar.uade.distribuidas.tpo.base.remoto.IGestionStock;


public class BS {
	public void publicarServicio() {
    	try {
    		LocateRegistry.createRegistry(Registry.REGISTRY_PORT);

    		IGestionRodamientos stubRodamientos = new GestionRodamiento();
			Naming.rebind("//localhost/GestionRodamientos", stubRodamientos);
			
			IGestionSolicitudDeCotizacion stubSolicitudDeCotizacion = new GestionSolicitudDeCotizacion();
			Naming.rebind("//localhost/GestionSolicitudDeCotizacion", stubSolicitudDeCotizacion);
			
			IGestionCotizacion stubCotizacion = new GestionCotizacion();
			Naming.rebind("//localhost/GestionCotizacion", stubCotizacion);
			
			IGestionListaPrecio stubListaPrecio = new GestionListaPrecio();
			Naming.rebind("//localhost/GestionListaPrecio", stubListaPrecio);
			
			
			IGestionStock stubStock = new GestionStock();
			Naming.rebind("//localhost/GestionStock", stubStock);
			verVinculos();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public void verVinculos() {
        try {
      	  String[] vinculos = Naming.list( "" );
      	  System.out.print(InetAddress.getLocalHost().getHostAddress());
      	  for ( int i = 0; i < vinculos.length; i++ ){
      		System.out.println( vinculos[i] );
      	  }
      	  System.out.print( ">>> Servicio DBA publicado");
        }
        catch (Exception e) {
      	  e.printStackTrace();
        }
     }
    
    public void cerrar() {
		try {
			Naming.unbind("GestionRodamientos");
		} catch (Exception e) {
		} finally {
			System.exit(0);
		}
    }
}


